package com.jyniubi.core.controller.api;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jyniubi.base.exception.Assert;
import com.jyniubi.base.result.R;
import com.jyniubi.base.result.ResponseEnum;
import com.jyniubi.core.pojo.entity.Dict;
import com.jyniubi.core.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 *
 * @author jyzhang
 * @since 2024-04-27
 */
@Api(tags = "借款人信息认证->填写借款人信息")
@RestController
@RequestMapping("/api/core/dict")
public class ApiDictController {
    @Resource
    private DictService dictService;
    @ApiOperation("查询借款人信息")
    @GetMapping("/dicts/{dictCode}")
    public R dicts(@PathVariable("dictCode")String dictCode){
        Dict dict = dictService.getOne(Wrappers.lambdaQuery(Dict.class).eq(Dict::getDictCode, dictCode));
        Assert.assertObjectIsNull(dict, ResponseEnum.ERROR);
        List<Dict> list = dictService.list(Wrappers.lambdaQuery(Dict.class).eq(Dict::getParentId, dict.getId()));
        return R.ok().data("items",list);
    }
}

